rm(list = ls())

setwd('/path/to/replication/')

library(data.table)
library(texreg)

# Table I2: Covid-19 Unemployment Effects on Asian Hate Crimes by Prejudice Controlling for Far-right Mayors

if (!file.exists('./output/out_econ_het_vshare_con_trend_all.RData') &
    !file.exists('./output/out_econ_het_vshare_con_trend_all_control_mayor.RData')) {
  source('./code/tableI2reg.R')
}

out_econ_het_vshare_con_trend_all <- get(load('./output/out_econ_het_vshare_con_trend_all.RData'))
out_econ_het_vshare_con_trend_all_add_controls <- get(load('./output/out_econ_het_vshare_con_trend_all_control_mayor.RData'))

tablei2 <- texreg(list(out_econ_het_vshare_con_trend_all, out_econ_het_vshare_con_trend_all_add_controls),
       include.ci = FALSE,
       stars = c(0.001, 0.01, 0.05, 0.1),
       digits = 5,
       include.adjrs = FALSE, include.rmse = FALSE,
               custom.coef.map = list('losing_income_d' = 'Expected unemployment', 'covid2'= 'After Jan, 2020',
                                      'extr_right_d' = 'High prejudice',
                                      'covid2:extr_right_d' = 'After Jan, 2020 x high prejudice',
                                      'losing_income_d:extr_right_d' = 'Unemployment x high prejudice',
                                      'covid2:losing_income_d' = 'After Jan, 2020 x unemployment',
                                      'covid_econ' = 'After Jan, 2020 x unemployment',
                                      'covid2:losing_income_d:extr_right_d' = 'After Jan, 2020 x unemployment x high prejudice'),
       symbol = "\\circ",
       caption = "Covid-19 Unemployment Effects on Asian Hate Crimes by Prejudice Controlling for Far-right Mayors",
       caption.above = TRUE)

write(tablei2, file.path('./tableI2.tex'))


# Table I3: Covid-19 Unemployment Effects on Asian Hate Crimes by Far-right Mayors Controlling for Prejudice

if (!file.exists('./output/out_econ_het_con_trend_all.RData') &
    !file.exists('./output/out_econ_het_con_trend_all_control_prejudice.RData')) {
  source('./code/tableI3reg.R')
}

out_econ_het_con_trend_all <- get(load('./output/out_econ_het_con_trend_all.RData'))
out_econ_het_con_trend_all_add_controls <- get(load('./output/out_econ_het_con_trend_all_control_prejudice.RData'))

tablei3 <- texreg(list(out_econ_het_con_trend_all, out_econ_het_con_trend_all_add_controls),
               include.ci = FALSE,
               include.adjrs = FALSE, include.rmse = FALSE,
               stars = c(0.001, 0.01, 0.05, 0.1),
               digits = 5,
               custom.coef.map = list('losing_income_d' = 'Expected unemployment', 'covid2'= 'After Jan, 2020',
                                      'extr_right_mayor' = 'Far-right mayor',
                                      'covid2:extr_right_mayor' = 'After Jan, 2020 x Far-right mayor',
                                      'losing_income_d:extr_right_mayor' = 'Unemployment x Far-right mayor',
                                      'covid2:losing_income_d' = 'After Jan, 2020 x Unemployment',
                                      'covid_econ' = 'After Jan, 2020 x Unemployment',
                                      'covid2:losing_income_d:extr_right_mayor' = 'After Jan, 2020 x Unemployment x Far-right mayor'),
               symbol = "\\circ",
               caption = "Table I3: Covid-19 Unemployment Effects on Asian Hate Crimes by Far-right Mayors Controlling for Prejudice",
               caption.above =  TRUE)

write(tablei3, file.path('./tableI3.tex'))
